package com.gitee.faster.webdav.kernel.model;

import com.gitee.faster.webdav.common.constant.Constants;
import jakarta.xml.bind.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author hongda.li
 */
@Data
@Accessors(chain = true)
@SuppressWarnings("SpellCheckingInspection")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "content"
})
@XmlRootElement(name = "getetag")
public class GetEtag {

    @XmlMixed
    private List<String> content;

    public static GetEtag byLengthAndDate(long length, Date date) {
        GetEtag etag = new GetEtag();
        etag.setContent(Collections.singletonList(String.format(Constants.E_TAG_TEMPLATE, length, date.getTime())));
        return etag;
    }
}
